//
//  EmoticonAttachment.swift
//  微博分支表情键盘
//
//  Created by JJ on 15/9/13.
//  Copyright © 2015年 JJ. All rights reserved.
//

import UIKit

class EmoticonAttachment: NSTextAttachment {

    var chs:String
    
    init(chs:String){
        self.chs=chs
        super.init(data: nil, ofType: nil)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    class func emoticonAttranbutetText(emoticon:Emoticon,font:UIFont)-> NSAttributedString {
        
        let attachMent=EmoticonAttachment(chs: emoticon.chs!)
        
        attachMent.image=UIImage(contentsOfFile: emoticon.imagePath)
        let h = font.lineHeight
        attachMent.bounds=CGRect(x: 0, y: -4, width: h, height: h)
        let imageStr=NSMutableAttributedString(attributedString: NSAttributedString(attachment: attachMent))
        imageStr.addAttribute(NSFontAttributeName, value: font, range: NSRange(location: 0, length: 1))
        return imageStr
        }
}
